//
//  LoginView.m
//  ShowMe
//
//  Created by 123 on 2018/8/22.
//  Copyright © 2018年 nkl. All rights reserved.
//

#import "LoginView.h"
@interface LoginView()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UIButton *headerIcon;
@property (weak, nonatomic) IBOutlet UITextField *phoneArea;
@property (weak, nonatomic) IBOutlet UITextField *pwdArea;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UIButton *forgotBtn;
@property (weak, nonatomic) IBOutlet UIButton *registnewBtn;

@end

@implementation LoginView

-(void)awakeFromNib{
    [super awakeFromNib];
    [self setUpUI];
}

-(void)layoutSubviews{
    [super layoutSubviews];

    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(__KNewSize(48));
        make.right.equalTo(self).offset(__KNewSize(-48));
        make.top.equalTo(self).offset(__KNewSize(112));
        make.bottom.equalTo(self.forgotBtn.mas_bottom).offset(__KNewSize(20));
    }];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(__KNewSize(43));
        make.centerX.equalTo(self);
    }];
    
    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(__KNewSize(40));
        make.centerX.equalTo(self.bgView);
        make.width.height.mas_equalTo(__KNewSize(90));
    }];
    
    [self.phoneArea mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.headerIcon.mas_bottom).offset(__KNewSize(30));
    }];
    
    [self.pwdArea mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.phoneArea.mas_bottom).offset(__KNewSize(30));
    }];
    
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.pwdArea.mas_bottom).offset(__KNewSize(30));
        make.height.mas_equalTo(__KNewSize(46));
    }];
    
    [self.forgotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.loginBtn);
        make.top.equalTo(self.loginBtn.mas_bottom).offset(__KNewSize(30));
    }];
    
    [self.registnewBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.bgView.mas_bottom).offset(__KNewSize(50));
        make.bottom.equalTo(self).offset(__KNewSize(-20));
    }];
}

-(instancetype)loadLoginViewFromXib{
    return  [[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil].lastObject;
}

-(void)setUpUI{
    //背景view
    self.bgView.layer.cornerRadius = 10;
    self.bgView.layer.shadowColor = CGColor(170, 170, 170, 1);
    self.bgView.layer.shadowOpacity = 1;
    self.bgView.layer.shadowOffset = CGSizeMake(0, 0);
    self.bgView.layer.shadowRadius = 20;
    self.bgView.layer.borderColor = [[UIColor colorWithRed:187/255.0 green:187/255.0 blue:187/255.0 alpha:1] CGColor];
    self.bgView.layer.borderWidth = 1;
    //头像
    self.headerIcon.layer.cornerRadius = __KNewSize(45);
    self.headerIcon.layer.masksToBounds = YES;
    //登录按钮
    self.loginBtn.layer.cornerRadius = 10;
    self.loginBtn.layer.masksToBounds = YES;
    
}
#pragma mark - clickEvent
- (IBAction)popToRegisterView:(id)sender {
    if ([self.delegate respondsToSelector:@selector(registButtonClick)]) {
        [self.delegate registButtonClick];
    }
}
- (IBAction)loginBtnClickEvent:(id)sender {
    if ([self.delegate respondsToSelector:@selector(loginButtonClick:password:)]) {
        [self.delegate loginButtonClick:self.phoneArea.text password:self.pwdArea.text];
    }
}
- (IBAction)forgetPwdBtnClickEvent:(id)sender {
    if ([self.delegate respondsToSelector:@selector(forgetButtonClick)]) {
        [self.delegate forgetButtonClick];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}

@end
